package com.googlecode.lohr.tools.interpreter;

import lohr.lang.dom.AbstractDOMVisitor;
import lohr.lang.dom.AccessModifier;
import lohr.lang.dom.CompilationUnit;
import lohr.lang.dom.Expression;
import lohr.lang.dom.IdentifierName;
import lohr.lang.dom.SlotDefinition;
import lohr.lang.dom.TypeReference;

/**
 * Completely qualifies all the names used in a compilation unit
 * @see the resolve method
 */
public class Resolver extends AbstractDOMVisitor {

	/**
	 * @return a new compilation unit where all the identifiers are fully qualified.
	 */
	public static CompilationUnit resolve(CompilationUnit unit) {
    	Resolver processor= new Resolver(unit);
        unit.accept(processor);
        return processor.getResult(unit);
    }
	
	CompilationUnit _unit;
    public Resolver(CompilationUnit unit) {
		_unit= unit;
	}
    
	public void visit(SlotDefinition slotDefinition) {
		String parentURI= findParentURI(slotDefinition);
		
		IdentifierName slotIdentifier= slotDefinition.getSlotIdentifier();
		
		AccessModifier modifier= getResult(match.findMatchByType(grammar.AccessModifier));
		Expression initExpresion= getResult(match.findMatchByType(grammar.Expression));
		IdentifierName name= getResult(match.findMatchByType(grammar.IdentifierName));
		TypeReference type= getResult(match.findMatchByType(grammar.TypeReference));
        putResult(new SlotDefinition(modifier, name, type, initExpresion));
	}	
    
    

}
